﻿using UnityEngine;
using Unity.Entities;
using Unity.Mathematics;

namespace Jinndev.Rendering2D {

    public struct AtlasTilingOffset : IComponentData {

        public static AtlasTilingOffset Default {
            get {
                return new AtlasTilingOffset {
                    value = new float4(1, 1, 0, 0),
                    tilingOffset = new float4(1, 1, 0, 0),
                    atlasTilingOffset = new float4(1, 1, 0, 0)
                };
            }
        }

        public float4 value;    // 最终值
        public float4 tilingOffset;  // 自身tilingOffset
        public float4 atlasTilingOffset;    // 如果开启自动图集，记录当前texture在自动图集中的tilingOffset，计算时加入到value中，因为job中不能读取config

        public AtlasTilingOffset(float4 tilingOffset, float4 atlasTilingOffset) {
            this.tilingOffset = tilingOffset;
            this.atlasTilingOffset = atlasTilingOffset;
            value = CommonUtil.ApplyAtlasTilingOffset(tilingOffset, atlasTilingOffset);
        }

        public void Apply(float4 tilingOffset) {
            this.tilingOffset = tilingOffset;
            value = CommonUtil.ApplyAtlasTilingOffset(tilingOffset, atlasTilingOffset);
        }

        public override string ToString() {
            return value.ToString();
        }

    }

    

}
